package com.atqh.srrt.chicken.config;


import com.atqh.srrt.chicken.handle.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {
//    注入拦截器
    @Autowired
    private LoginInterceptor loginInterceptor;

    /*@Override
    public void addCorsMappings(CorsRegistry registry) {
        //跨域配置
        registry.addMapping("/**").allowedOrigins("http://localhost:8080");
    }*/

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
//                .addPathPatterns("*").excludePathPatterns("/login").excludePathPatterns("/register")
                .addPathPatterns("/articles/view/{id}")
                .addPathPatterns("/article/{id}")
                .addPathPatterns("/articles/publish")
                .addPathPatterns("/comments/article/{id}")
                .addPathPatterns("/comments/create/change")
                .addPathPatterns("/qaSelect/*")
                .addPathPatterns("/videoes/*")
                .addPathPatterns("/test1/*").excludePathPatterns("/test1/upload");
    }

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
}
